<?php
namespace shenka\controllers;

use Yii;
use yii\web\Controller;
use shenka\models\User;
use shenka\models\Art;
use shenka\models\ArtUser;
use shenka\models\Edition;
use shenka\models\EditionUser;
use shenka\models\UserLogin;
use shenka\models\EditionKrDev;
use shenka\models\EditionKrLogin;
/*
* @author admin 
* @class Edition
* @desc 神卡系列数据总览
*/
class IndexController extends Controller {
	/*
	* @author admin 
	* @function index
	* @desc 神卡系列数据总览
	*/
    public $layout = 'second';
	public function actionIndex(){
        
		$view = Yii::$app->view;
		$view->params['layout_data'] = '神卡王国国系列';
        //当日零点时间戳、昨日零点时间戳、明日零点时间戳、
        $time = mktime(0,0,0,date("m",time()),date("d",time()),date("Y",time()));
        $time_old = mktime(0,0,0,date("m",time()),date("d",time())-1,date("Y",time()));
        $time_new = mktime(0,0,0,date("m",time()),date("d",time())+1,date("Y",time()));
        //国内数据
        //总注册
        $totalreg = User::find()->count();
        //总激活=星球（中）+美术棒
        //总登录
        $totallog = UserLogin::find()->count();
        //总占比=星球（中）+美术棒
        //昨日注册
        $reg_past = User::find()->where(['between','register_time',"$time_old","$time"])->count();
        //昨日登录
        $log_past = UserLogin::find()->andWhere(['between','create_time',"$time_old","$time"])->count();
        //今日注册
        $reg_today = User::find()->where(['between','register_time',"$time","$time_new"])->count();
        //今日登陆    
        $log_today = UserLogin::find()->andWhere(['between','create_time',"$time","$time_new"])->count();
        
        //星球大冒险(中)
        //总激活
        $ch_act = Edition::find()->count('active_time');
        //Android/iOS占有
        $ch_android = EditionUser::find()->where(['device'=>'android'])->count();
        $ch_ios = EditionUser::find()->where(['device'=>'iphone'])->count();
        //昨日激活
        $ch_act_past = Edition::find()->where(['between','active_time',"$time_old","$time"])->count('active_time');
        //Android/iOS占有
        $ch_act_past_android = EditionUser::find()->where(['device'=>'android'])->andWhere(['between','create_time',"$time_old","$time"])->count();
        $ch_act_past_ios = EditionUser::find()->where(['device'=>'iphone'])->andWhere(['between','create_time',"$time_old","$time"])->count();
        //今日激活
        $ch_act_today = Edition::find()->where(['between','active_time',"$time_old","$time"])->count('active_time');
        //Android/iOS占有
        $ch_act_today_android = EditionUser::find()->where(['device'=>'android'])->andWhere(['between','create_time',"$time","$time_new"])->count();
        $ch_act_today_ios = EditionUser::find()->where(['device'=>'iphone'])->andWhere(['between','create_time',"$time","$time_new"])->count();
       
        //美术棒
        //总激活
        $act_art = Art::find()->count('active_time');
       	//Android/iOS占有
        $art_android = ArtUser::find()->where(['device'=>'android'])->count();
        $art_ios = ArtUser::find()->where(['device'=>'iphone'])->count();
        //昨日激活
        $art_act_past = Art::find()->where(['between','active_time',"$time_old","$time"])->count('active_time');
        //Android/iOS占有
        $art_act_past_android = ArtUser::find()->where(['device'=>'android'])->andWhere(['between','create_time',"$time_old","$time"])->count();
        $art_act_past_ios = ArtUser::find()->where(['device'=>'iphone'])->andWhere(['between','create_time',"$time_old","$time"])->count();
        //今日激活
        $art_act_today = Art::find()->where(['between','active_time',"$time_old","$time"])->count('active_time');
        //Android/iOS占有
        $art_act_today_android =ArtUser::find()->where(['device'=>'android'])->andWhere(['between','create_time',"$time","$time_new"])->count();
        $art_act_today_ios = ArtUser::find()->where(['device'=>'iphone'])->andWhere(['between','create_time',"$time","$time_new"])->count();
        
        //星球大冒险（韩）
        //总激活产品
        $kr_prod = EditionKrDev::find()->groupBy('prod_code_id')->count('prod_code_id');
        //总激活设备
        $kr_dev = EditionKrDev::find()->count('id');
       	//Android/iOS占有
        $kr_android = EditionKrDev::find()->where(['device'=>'android'])->count();
        $kr_ios = EditionKrDev::find()->where(['device'=>'iphone'])->count();
        //昨日激活产品
        $kr_prod_past = EditionKrDev::find()->where(['between','create_time',"$time_old","$time"])->groupBy('prod_code_id')->count('prod_code_id');
        //昨日激活设备
        $kr_dev_past = EditionKrDev::find()->where(['between','create_time',"$time_old","$time"])->count('prod_code_id');
        //Android/iOS占有
        $kr_past_android = EditionKrDev::find()->where(['device'=>'android'])->andWhere(['between','create_time',"$time_old","$time"])->count('prod_code_id');
        $kr_past_ios = EditionKrDev::find()->where(['device'=>'iphone'])->andWhere(['between','create_time',"$time_old","$time"])->count('prod_code_id');
        //今日激活产品
        $kr_prod_today = EditionKrDev::find()->where(['between','create_time',"$time_old","$time"])->groupBy('prod_code_id')->count('prod_code_id');
        //今日激活设备
        $kr_dev_today = EditionKrDev::find()->where(['between','create_time',"$time_old","$time"])->count('prod_code_id');
        //Android/iOS占有
        $kr_today_android = EditionKrDev::find()->where(['device'=>'android'])->andWhere(['between','create_time',"$time","$time_new"])->count('prod_code_id');
        $kr_today_ios = EditionKrDev::find()->where(['device'=>'iphone'])->andWhere(['between','create_time',"$time","$time_new"])->count('prod_code_id');
        $data['data'] = [
        //国内数据
        'totalreg'=>$totalreg,
        'totallog'=>$totallog,
        'reg_past'=>$reg_past,
        'log_past'=>$log_past,
        'reg_today'=>$reg_today,
        'log_today'=>$log_today,
        //星球大冒险（中）
        'ch_act'=>$ch_act,
        'ch_android'=>$ch_android,
        'ch_ios'=>$ch_ios,
        'ch_act_past'=>$ch_act_past,
        'ch_act_past_android'=>$ch_act_past_android,
        'ch_act_past_ios'=>$ch_act_past_ios,
        'ch_act_today'=>$ch_act_today,
        'ch_act_today_android'=>$ch_act_today_android,
        'ch_act_today_ios'=>$ch_act_today_ios,
        //美术棒
        'act_art'=>$act_art,
        'art_android'=>$art_android,
        'art_ios'=>$art_ios,
        'art_act_past'=>$art_act_past,
        'art_act_past_android'=>$art_act_past_android,
        'art_act_past_ios'=>$art_act_past_ios,
        'art_act_today'=>$art_act_today,
        'art_act_today_android'=>$art_act_today_android,
        'art_act_today_ios'=>$art_act_today_ios,
        //星球大冒险（韩）
        'kr_prod'=>$kr_prod,
        'kr_dev'=>$kr_dev,
        'kr_android'=>$kr_android,
        'kr_ios'=>$kr_ios,
        'kr_prod_past'=>$kr_prod_past,
        'kr_dev_past'=>$kr_dev_past,
        'kr_past_android'=>$kr_past_android,
        'kr_past_ios'=>$kr_past_ios,
        'kr_prod_today'=>$kr_prod_today,
        'kr_dev_today'=>$kr_dev_today,
        'kr_today_android'=>$kr_today_android,
        'kr_today_ios'=>$kr_today_ios
        ];
       
        return $this->render('index',$data);
	}
}